namespace YasharEl.Infrastructure.ArchitectureTools.AppModelerLib.Commands
{
    using System.ComponentModel;
    using System.ComponentModel.Composition;
    using Microsoft.VisualStudio.TeamArchitect.PowerTools.Ultimate.Features;
    using Microsoft.VisualStudio.Shell;
    using EnvDTE;

    [DisplayName("CreateAllSolutionFoldersCommand")]
    [Description("CreateAllSolutionFoldersCommand Description")]
    public class CreateAllSolutionFoldersCommand : FeatureCommand
    {
        // Declared public properties will be exposed in the Command Bindings property

        /// <summary>
        /// Gets the Feature Extension instance for this invocation
        /// of the Condition
        /// </summary>
        [Import(AllowDefault = true)]
        public IFeatureExtension Feature { get; private set; }

        /// <summary>
        /// Gets and sets the ServiceProvider using MEF
        /// </summary>
        [Import]
        public SVsServiceProvider ServiceProvider { get; set; }

        /// <summary>
        /// Called when any launch point bound to a command binding which refers to this command
        /// is invoked
        /// </summary>
        /// <param name="feature">Instance of Feature Extension which is invoking the command</param>
        public override void Execute()
        {
            var dte = ServiceProvider.GetService(typeof(DTE)) as EnvDTE.DTE;

            if (dte == null)
                return;

            if (dte.Solution != null)
            {
                EnvDTE100.Solution4 vs2010Solution = dte.Solution as EnvDTE100.Solution4;
                if (vs2010Solution != null)
                {
                    vs2010Solution.AddSolutionFolder("Libs");
                    vs2010Solution.AddSolutionFolder("Design");
                    vs2010Solution.AddSolutionFolder("Tests");
                    vs2010Solution.AddSolutionFolder("Applications");
                    vs2010Solution.AddSolutionFolder("Bounded Contexts");

                    BlackboardManager.Current.Set("SolutionFoldersCreated", "True");
                }

                dte.StatusBar.Text = "Solution folders created for solution : " + vs2010Solution.FullName;
            }
        }
    }
}